#include "ModelList.h"

using namespace Graphics;

ModelList::ModelList(void)
	:mModelCount(0),
	 mModelInfoList(NULL)
{
}

ModelList::~ModelList(void)
{
}

bool ModelList::Initialize(int numModels)
{
	float red, green, blue;
	// Store the number of models.
	mModelCount = numModels;

	// Create a list array of the model information.
	mModelInfoList = new ModelInfoType[mModelCount];
	if(!mModelInfoList)
	{
		return false;
	}

	// Seed the random generator with the current time.
	srand((unsigned int)time(NULL));

	// Go through all the models and randomly generate the model color and position.
	for(int i=0; i < mModelCount; i++)
	{
		// Generate a random color for the model.
		red = (float)rand() / RAND_MAX;
		green = (float)rand() / RAND_MAX;
		blue = (float)rand() / RAND_MAX;

		mModelInfoList[i].color = D3DXVECTOR4(red, green, blue, 1.0f);

		// Generate a random position in front of the viewer for the mode.
		mModelInfoList[i].positionX = (((float)rand()-(float)rand())/RAND_MAX) * 10.0f;
		mModelInfoList[i].positionY = (((float)rand()-(float)rand())/RAND_MAX) * 10.0f;
		mModelInfoList[i].positionZ = ((((float)rand()-(float)rand())/RAND_MAX) * 10.0f) + 5.0f;
	}

	return true;
}

void ModelList::Deinitialize()
{
	// Release the model information list.
	if(mModelInfoList)
	{
		delete [] mModelInfoList;
		mModelInfoList = 0;
	}
}

int ModelList::GetModelCount()
{
	return mModelCount;
}

void ModelList::GetData(int index, float& positionX, float& positionY, float& positionZ, D3DXVECTOR4& color)
{
	positionX = mModelInfoList[index].positionX;
	positionY = mModelInfoList[index].positionY;
	positionZ = mModelInfoList[index].positionZ;
	color = mModelInfoList[index].color;
}